﻿// Problems From http://www.ProjectEuler.net
//
// These problems are for the c# vs f# challenge:
//  10, 12, 25, 27, 36, 40
//
#light

open System
open System.Diagnostics

let time f =
    let watch = new Stopwatch()
    watch.Start()
    let res = f()
    watch.Stop()
    (res, watch.ElapsedMilliseconds)

let solveProblem n f =
    printfn "Problem %d" n
    let (answer, timing) = time f
    printfn "  Answer = %A\n  Timing = %A \n" answer timing
    
let makeSolver nu fu =
    (nu.ToString(), fun () -> solveProblem nu fu)

let problems = [
    makeSolver 1 Problem001.solve; makeSolver 2 Problem002.solve 
    makeSolver 10 Problem010.solve; makeSolver 12 Problem012.solve; 
    makeSolver 13 Problem013.solve; makeSolver 25 Problem025.solve; 
    makeSolver 36 Problem036.solve; makeSolver 40 Problem040.solve; ]
    
let args = Environment.GetCommandLineArgs()
if args.Length > 1 then 
    for p in problems do
        match p with
        | (num,solve) when num = args.[1]-> solve()
        | _ -> ()
else        
    for (_,solve) in problems do solve()    

printfn "\n\nComplete - press Return."

open System
ignore <| Console.ReadKey(true)